#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

#define DISPLAY_TIME_PORT  25045
#define FTP_SERVICE_PORT 20450 
#define REMOTE_COM_SERVICE_PORT 15450 
#define SIZE 512

int flag;
int sigflag;

int err_stop (char* msg)
{
	printf("%s \n",msg);
	//exit(-1);
}

int resquiescat(){wait();sigflag = 1;}

int resquiescats(){wait();flag = 1;}

int max( int a,int b,int c){
	int max =a,tmp=c;
	if(a > b)
		max = a;
	else
		max = b;	
	if(max > c)
		tmp = max;
	return tmp;
}

int main(int argc, char*argv[ ] ){
	
	sigset(SIGCHLD, resquiescats);
	
	int list_services[]={-1,-1,-1};
	
	
	int pid = fork();
    if(pid == 0){
    	char *args[2];
    	flag = 0;
    	list_services[1] = 1;
    	sigset(SIGCHLD, resquiescat);//signal
    	//printf("SERVER ADDRESS : %s \n", (char*)inet_ntoa(serv_addr_2));
		//printf("SERVER PORT : %d \n", REMOTE_COM_SERVICE_PORT);
		//int childpid;
		int sockfd,clilen,n,childpid_2;
		int sigflag,clilen_2,sd3;
		char msg[SIZE];
			
    	args[0] = "./serveurProcess";
    			
    	//sprintf(args[1],"%d",sockfd_2);
    	args[1] = NULL;
    
    	int r = execv("./serveurProcess",args);
    	//exit(0);
    }
    //printf("Processus en cours d'execution \n");
    int pid1 = fork();
    if(pid1 == 0){//ouverture du second cannal
    	//dup();
    	flag = 0;
    	sleep(5);
    	sigset(SIGCHLD, resquiescat);//signal
    	printf("Processus en cours d'execution .... My processus id %d and my Perent id %d \n",getpid(),getppid());
    	printf("Processus en cours d'execution .... \n");
    	char *args[2];
    	flag = 0;
    	args[0] = "./serveur_Time";
    			
    	//sprintf(args[1],"%d",sockfd_2);
    	args[1] = NULL;
    
    	int r = execv("./serveur_Time",args);
   }
   
   char *argsv[2];
   argsv[0] = "./serveurFTP";
    			
    	//sprintf(args[1],"%d",sockfd_2);
   argsv[1] = NULL;
    
   int s = execv("./serveurFTP",argsv);
   
 
}
